package com.gitee.wsl.compose.ui.portal

import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.scaleIn
import androidx.compose.animation.scaleOut
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.animation.slideOutVertically
import androidx.compose.runtime.Immutable

@Immutable
data class PortalTransition(
  val enter: EnterTransition,
  val exit: ExitTransition,
) {
   companion object {
     fun enter(
      enter: EnterTransition,
    ): PortalTransition = PortalTransition(
      enter = enter,
      exit = ExitTransition.None,
    )

     fun exit(
      exit: ExitTransition,
    ): PortalTransition = PortalTransition(
      enter = EnterTransition.None,
      exit = exit,
    )

     val defaultEnter: EnterTransition = slideInHorizontally(
      initialOffsetX = { it * 2 },
    )

     val defaultExit: ExitTransition = slideOutHorizontally(
      targetOffsetX = { -it },
    )

     val defaultBackstackPushEnter: EnterTransition = fadeIn()

     val defaultBackstackPopExit: ExitTransition = fadeOut()

     val defaultAttach: EnterTransition = slideInVertically(
      initialOffsetY = { -it },
    )

     val defaultDetach: ExitTransition = slideOutVertically(
      targetOffsetY = { it * 2 },
    )

     val defaultBackstackPushAttach: EnterTransition = fadeIn()

     val defaultBackstackPushDetach: ExitTransition = fadeOut()

     val defaultBackstackPopAttach: EnterTransition = scaleIn()

     val defaultBackstackPopDetach: ExitTransition = scaleOut()

     val None: PortalTransition = PortalTransition(
      enter = EnterTransition.None,
      exit = ExitTransition.None,
    )
  }
}
